package com.ctshk.app.air.controller;

import com.ctshk.common.annotations.OperationLogAnnotation;
import com.ctshk.common.dto.Result;
import com.ctshk.common.enums.ChannelMainData;
import com.ctshk.common.enums.OperationLogModel;
import com.ctshk.common.enums.OperationLogType;
import com.ctshk.common.web.support.BaseController;
import com.ctshk.rpc.air.dto.MainDataAirAirportDTO;
import com.ctshk.rpc.air.dto.app.AirProductDetailDTO;
import com.ctshk.rpc.air.dto.app.HomePageDataDto;
import com.ctshk.rpc.air.dto.pc.HotCityDTO;
import com.ctshk.rpc.air.dto.app.MainDataRowFieldDataDTO;
import com.ctshk.rpc.air.dto.pc.AirFlightListDTO;
import com.ctshk.rpc.air.req.AirPortListReq;
import com.ctshk.rpc.air.req.app.AirTicketsListReq;
import com.ctshk.rpc.air.req.app.MainDataRowFieldDataReq;
import com.ctshk.rpc.air.service.IAirProductCostTouristService;
import com.ctshk.rpc.air.service.app.IAirProductAppService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.time.LocalDate;
import java.util.List;
import java.util.Optional;

/**
 * @BelongsProject: ctshk-cloud
 * @BelongsPackage: com.ctshk.app.air.controller
 * @Author: hef
 * @CreateTime: 2021-04-16 09:55
 * @Description: 描述
 */
@Api(value = "PC机票产品", tags = "PC机票产品")
@RestController
@RequestMapping("/pc-air-product")
public class PcAirProductController extends BaseController {

    @DubboReference
    private IAirProductAppService iAirProductAppService;

    @DubboReference
    private IAirProductCostTouristService iAirProductCostTouristService;

    @ApiOperation(value = "查询机票列表", notes = "查询机票列表")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.QUERY, operTitle = "查询机票列表", operDesc = "查询机票列表")
    @PostMapping("/getTicketList")
    public Result<List<AirFlightListDTO>> getTicketList(@RequestBody AirTicketsListReq req) {
        return Result.success(iAirProductAppService.getPcTicketList(req));
    }

 /*   @ApiOperation(value = "查询推荐机票", notes = "查询推荐机票")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.QUERY, operTitle = "查询推荐机票", operDesc = "查询推荐机票")
    @GetMapping("/getRecommendedTicket")
    public Result<List<AirRecommendListDTO>> getRecommendedTicket() {
        return Result.success(iAirProductAppService.getRecommendedTicket());
    }*/

    @ApiOperation(value = "获取机票详情", notes = "获取机票详情")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.QUERY, operTitle = "获取机票详情", operDesc = "获取机票详情")
    @GetMapping("/getProductDetail/{id}")
    public Result<AirProductDetailDTO> getProductDetail(@PathVariable(value = "id") Long id,
                                                        @RequestParam(value = "date", required = false) LocalDate date) {
        return Result.success(iAirProductAppService.getProductDetail(id, Optional.ofNullable(date).orElse(LocalDate.now()), ChannelMainData.APP_H5.getId()));
    }

    @GetMapping("/getHomePageData")
    @ApiOperation(value = "获取机票首页数据", notes = "获取机票首页数据")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.QUERY, operTitle = "获取机票首页数据", operDesc = "获取机票首页数据")
    public Result<HomePageDataDto> getHomePageData() {
        return Result.success(iAirProductAppService.getHomePageData());
    }

    @PostMapping("/query/fieldLike/name")
    @ApiOperation(value = "航空公司和仓位等级", notes = "根据行id和字段id查询值,去重主数据")
    @OperationLogAnnotation(operModul = OperationLogModel.SYSTEM, operType = OperationLogType.QUERY, operTitle = "根据行id和字段id查询值和名称模糊", operDesc = "内部接口，根据行id和字段id查询值")
    public Result<List<MainDataRowFieldDataDTO>> queryFieldLikeName(@RequestBody @Valid MainDataRowFieldDataReq req) {
        return Result.success(iAirProductAppService.queryFieldLikeName(req));
    }


    @PostMapping("/getMonthFloorPrice")
    @ApiOperation(value = "获取一个月内的最低价格", notes = "获取一个月内的最低价格")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET,
            operType = OperationLogType.QUERY, operTitle = "获取一个月内的最低价格", operDesc = "获取一个月内的最低价格")
    public Result getMonthFloorPrice(@RequestBody AirTicketsListReq req) {
        return Result.success(iAirProductAppService.getMonthFloorPrice(req.setChannelId(ChannelMainData.CHINA_TRAVEL.getId())));
    }

    @PostMapping("/getAirportList")
    @ApiOperation(value = "获取机场信息", notes = "搜索获取机场信息")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.QUERY, operTitle = "获取机场信息", operDesc = "获取机场信息")
    public Result<List<MainDataAirAirportDTO>> getAirportList(@RequestBody AirPortListReq req) {
        return Result.success(iAirProductAppService.getAirportList(req));
    }

    @GetMapping("/getHotCity")
    @ApiOperation(value = "获取热门城市数据", notes = "获取热门城市数据")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.QUERY, operTitle = "获取热门城市数据", operDesc = "获取热门城市数据")
    public Result<HotCityDTO> getHotCity(){
        return Result.success(iAirProductAppService.getHotCity());
    }

    @ApiOperation(value = "获取机票旅客类型", notes = "获取机票旅客类型")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.ADD, operTitle = "获取机票旅客类型", operDesc = "获取机票旅客类型")
    @PostMapping("/query/touristtype")
    public Result queryTouristType() {
        return iAirProductCostTouristService.queryTouristType();
    }
}
